<template>
    <div>
        <el-row>
            <el-col :span="2">
                付款方式：
            </el-col>
            <el-col :span="4">
                预付
            </el-col>
            <el-col :span="2">
                余额：
            </el-col>
            <el-col :span="4">
                12.42
            </el-col>
            <el-col :span="2">
                信用额度：
            </el-col>
            <el-col :span="4">
                12.42
            </el-col>
            <el-button type="primary" @click="dialogVisible = true">收取/支付塔扬科技</el-button>
            <el-button type="primary" @click="dialogVisible1 = true">调整信用额度</el-button>
            <Pay :dialogVisible="dialogVisible" @dialogColse="dialogColse"/>
        </el-row>
        <el-dialog title="信用额度" :visible.sync="dialogVisible1" width="40%">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
                <el-form-item label="当前信用额度：">
                    <el-input v-model="ruleForm.current" auto-complete="off" :disabled="true"> </el-input>
                </el-form-item>
                <el-form-item label="新信用额度：" prop="new">
                    <el-input v-model="ruleForm.new" auto-complete="off"> </el-input>
                </el-form-item>
                <el-form-item label="备注：">
                    <el-input v-model="ruleForm.beizhu" auto-complete="off"> </el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="resetForm('ruleForm')">取 消</el-button>
                <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
            </span>
        </el-dialog>
        <el-tabs @tab-click="handleClick" v-model="activeName">
            <el-tab-pane v-for="(tab, index) in tabData" :label="tab.label" :name="tab.name" :key="index"></el-tab-pane>
        </el-tabs>
        <router-view></router-view>
    </div>
</template>

<script>
    import Pay from '@/base/pay/pay'
   export default {
        data() {
            return {
                dialogVisible: false,
                tabData: [{
                        label: '订单信息',
                        name: 'agent_order_statistics'
                    },
                    {
                        label: '收付款记录',
                        name: 'order_incomes'
                    },
                    {
                        label: '账户余额',
                        name: 'company_agent_orders'
                    }
                ],
                dialogVisible1: false,
                activeName: 'agent_order_statistics',
                ruleForm: {
                    current: '',
                    new: '',
                    beizhu: ''
                },
                rules: {
                    new: [
                        {
                            required: true,
                            message: '请输入新信用额度',
                            trigger: 'blur'
                        }, 
                        {
                            pattern: /^\d+(\.\d{1,2})?$/,
                            message: '请输入两位小数'
                        }
                    ]
                }
            }
        },
        created() {
            this.activeName = this.$route.name
            if(this.$route.fullPath.includes('order_incomes')) {
                this.activeName = 'order_incomes'
            }
        },
        methods: {
            handleClick(tab) {
                var path = '/agent_increase/' + this.$route.params.id9+ '/agent_order_statistics/' + tab.name
                if (tab.name === 'agent_order_statistics') {
                    path = '/agent_increase/' + this.$route.params.id9 + '/agent_order_statistics';
                }
                this.$router.push({
                    path: path
                })
            },
            dialogColse() {
                this.dialogVisible = false
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.dialogVisible1 = false
            },

        },
        watch: {
            $route: {
                handler: function(to) {
                    console.log(to.name)
                    this.tabData.forEach((tab) => {
                        if (tab.name == to.name) {
                            this.activeName = to.name
                        }
                    });
                },
                // 深度观察监听
                deep: true
            }
        },
        components: {
            Pay
        }
    }
</script>

<style scoped lang="scss">
    .el-row {
        position: relative;
        .el-col {
            font-size: 14px;
            padding: 15px 0px;
        }
        .el-col:nth-of-type(2n + 1) {
            font-weight: bold;
            text-align: left;
        }
        .el-col:nth-of-type(2n) {
            padding-left: 15px;
        }
        .el-button:nth-of-type(1){
            position: absolute;
            top: 8px;
            right: 130px;
        }

        .el-button:nth-of-type(2){
            position: absolute;
            top: 8px;
            right: 0px;
        }
    }
</style>